import React, { Component } from 'react'

export class Login extends Component {
    state={
        userValue:"",
        passWord:""
    }
    
    editUser(e){
        this.setState({userValue:e.target.value})
    }

    editPass(e){
        this.setState({passWord:e.target.value})
    }

    btn(){
        let obj={}
        obj.user = this.state.userValue
        obj.password = this.state.passWord
        localStorage.setItem("token",JSON.stringify(obj))
        this.props.history.push("/")
    }   

    render() {
        let {userValue,passWord} = this.state
        console.log(userValue,passWord);
        return (
            <div>
                Login
                <br/>
                用户名：<input type="text" value={userValue} onChange={this.editUser.bind(this)}/>
                <br/>
                密码:<input type="password" value={passWord} onChange={this.editPass.bind(this)}/>
                <button onClick={this.btn.bind(this)}>登录</button>
            </div>
        )
    }
}

export default Login
